#coding=utf8
import urllib2, re, sys, urlparse

myre = re.compile('<div class=\"fn3c\"><a href=\"(.*?)\" target="_blank" title="">(.*?)</a></div>')
# <div class="fn3c"><a href="/m/tian-jiang-zhi-wu/1/1/" target="_blank" title="">

def getchapter(url,name="unamed",mylog=None):
    "parser html source to generate chapterlist"
    chapterlist = []
    content = ''
    try:
        content = urllib2.urlopen(url).read()
        if content:
            for item in myre.findall(content):
                title = item[1].decode('gbk').encode('utf-8')
                chapterlist.append([urlparse.urljoin(url, item[0]), title])
        return chapterlist
    except  Exception, e:
        if mylog:
            mylog.writeLog(str(e)+'in getchapter','error')
        return None
    
